﻿using Application;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Web.AdminLTE.Filter;

namespace Web.AdminLTE.Controllers
{
    public class BaseController : Controller
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            byte[] result;
            filterContext.HttpContext.Session.TryGetValue("CurrentUser", out result);
            if (result == null)
            {
                //filterContext.Result = new RedirectResult("/Login/Index");
                filterContext.Result = RedirectToRoute("Default", new { Controller = "Login", Action = "Index" });
                return;
            }
            base.OnActionExecuting(filterContext);

            Guid userID;
            Guid.TryParse(HttpContext.Session.GetString("CurrentUserID"), out userID);
            ViewBag.UserID = userID;
        }
    }
}
